import React, { Component } from 'react';
import { createPage, base, getMultiLang } from 'nc-lightapp-front';
import { setTable } from '../../../sscrppublic/common/utils/setComponentUsed';
const { NCModal } = base;

import linkQueryApi from "./requestApi";

/**
 * 联查费用申请单
 */
const templateCode = 'jkdBillModel';
let isLoadTemplate = false;
class LinkChangeModel extends Component {

    constructor(props) {
        super(props);
        setTable(props, templateCode);

        this.state = {
            multiLang : {}
        }
        getMultiLang({moduleId: 1056, domainName: 'sscrp',currentLocale: 'zh-CN', callback: (json) => {
            this.setState({
                multiLang : json
            })
        }})
    }

    componentWillReceiveProps(nextProps) {
        const props = this.props;
        if (nextProps.show && !isLoadTemplate) {
            isLoadTemplate = true;
            props.createUIDom(
                {
                    appcode: '201102JCLF',
                    pagecode: '201102JCLF_LCBX'
                },
                function (data) {
                    props.meta.setMeta(data.template);
                    props.table.setTableRender(templateCode, 'djbh', (text, record, index) => {
                        return (
                            <a
                                className='hyperlinks'
                                onClick={() => {
                                    linkQueryApi.link({
                                        data: {
                                            openbillid : record.pk_mtapp_bill.value,
                                            tradetype : record.pk_tradetype.value,
                                            props: props
                                        }
                                    });
                                }}
                            >
                                {' '}{record.djbh.value}{' '}
                            </a>
                        );
                    });
                }
            );
        }
    }

    queryData = () => {
        const { table } = this.props;
        table.setAllTableData(templateCode, this.props.linkData.data[templateCode]);
    }

    onRowDoubleClick = record => {
        linkQueryApi.link({
            data : {
                openbillid : record.pk_mtapp_bill.value,
                tradetype : record.pk_tradetype.value,
                props : this.props
            }
        });
    }

    render() {

        const { show, close, table } = this.props;
        const { createSimpleTable  } = table;

        return (
            <NCModal fieldid='link-jkbx' show={show} size='xlg' onEnter={this.queryData}>
                <NCModal.Header  closeButton={true} onHide={() =>close()}>
                    {"联查变更"}
                </NCModal.Header>
                <NCModal.Body>
                    <div className="nc-single-table">
                    {createSimpleTable(templateCode, {
                        showIndex: true,
                        onRowDoubleClick: this.onRowDoubleClick
                    })}
                    </div>
                </NCModal.Body>
            </NCModal>
        );
    }
}

export default createPage({})(LinkChangeModel);